﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using System.Data.SqlClient;
using System.Data.Common;

public partial class SearchResults : System.Web.UI.Page
{
    Microsoft.Practices.EnterpriseLibrary.Data.Database db = DatabaseFactory.CreateDatabase("Application_Data");

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            TextBox MasterPageTextBox = (TextBox)Master.FindControl("txtSearch");
            MasterPageTextBox.Text = Request.QueryString["SearchText"].ToString();
        }

        this.gvResults.Visible = true;
        
        DataSet ds = db.ExecuteDataSet(CommandType.Text, "SELECT InstanceName,DatabaseName FROM [Database] WHERE DatabaseName like '%" + Request.QueryString["SearchText"].ToString() + "%' OR InstanceName like '%" + Request.QueryString["SearchText"].ToString() + "%'");

        this.gvResults.DataSource = ds;
        this.gvResults.DataBind();

        if (this.gvResults.Rows.Count < 1)
        {
            MessageBox.Show("No results found, revise search criteria");
        }
        
    }
}
